<?php
$this->breadcrumbs=array(
    'Widgets'=>array('/Cms/admin/widget/admin'),
    'Data Unused',
);

$grid = $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'widget-data-grid',
    'dataProvider'=>$model->unused(),
    'filter'=>$model,
    'selectableRows'=>2,
    'columns'=>array(
        array(
            'class'=>'CCheckBoxColumn',
            'value'=>'$data->id',
            'htmlOptions'=>array('width'=>'3%'),
        ),
        array(
            'name'=>'name',
            'type'=>'html',
            'value'=>'CHtml::link($data->name, array("/Cms/admin/widget/updateInstance", "instanceId"=>$data->id, "id"=>$data->widget_id), array("title"=>$data->name))',
        ),
        array(
            'name'=>'widget_id',
            'type'=>'html',
            'value'=>'is_object($data->widget) ? CHtml::link($data->widget->name, array("/Cms/admin/widget/update", "id"=>$data->widget_id), array("title"=>$data->widget->name)) : ""',
            'filter'=>$model->getFilterWidgetUnused(),
        ),
        array(
            'name'=>'creation_datetime',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->creation_datetime))',
            'filter'=>false,
            'htmlOptions'=>array(
                'class'=>'datetime-column'
            )
        ),
        array(
            'name'=>'last_update',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->last_update))',
            'filter'=>false,
            'htmlOptions'=>array(
                'class'=>'datetime-column'
            )
        ),
        array(
            'class'=>'CButtonColumn',
            'updateButtonUrl'=>'Yii::app()->controller->createUrl("/Cms/admin/widget/updateInstance", array("instanceId"=>$data->id, "id"=>$data->widget_id))',
            'template'=>'{update} {delete}',
        ),
    ),
));

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url'=>$this->createUrl('delete'), 'linkOptions' => array('onclick'=>'return multipleDelete("widget-data-grid",this.href)'));
    Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl.'/scripts/gridview.js');
}